/*
 * igo: com.cctv.igo.admin.scheduler.dto.Task.java Create On 2011-5-4 下午09:41:30 By Q-Wang
 * $Revision: 1.2 $
 */
package com.ctvit.scheduler.dto;

import org.quartz.JobDetail;

import com.ctvit.scheduler.common.Copier;
import com.ctvit.scheduler.domain.QrtxTask;
import com.ctvit.framework.web.context.ContextHolder;

/**
 * @author <a href="mailto:apeidou@gmail.com">Q-Wang</a>
 *
 */
public class Task extends QrtxTask {

	public Task() {}

	public Task(QrtxTask task) {
		populate(task);
	}

	public void populate(QrtxTask task) {
		Copier.COPIER_TASK.copy(task, this, null);
	}

	public JobDetail createJob() {
		if(getDefinition()==null){
			return null;
		}
		JobDetail detail = ContextHolder.getBean(getDefinition());
		return detail;
//		try {
			//detail = new JobDetail(getName(), Class.forName(getDefinition()));
//			return detail;
//		} catch (ClassNotFoundException e) {
//			e.printStackTrace();
//		}
//		return null;
	}

	public void setEnabledBoolean(boolean enabled) {
		setEnabled(enabled?1:0);
	}

	public boolean getEnabledBoolean() {
		return getEnabled()!=0;
	}
}
